 

import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.*;
/**
 * Write a description of class Asteroid here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Asteroid extends Actor
{
    private static Counter score;
    
    public Asteroid(Counter counter)
    {
        score = counter;
    }
    
    public void act() 
    {
        try{
            destroyShip();
            leaveWorld();
            if (getWorld() != null)  vertMove();
        }
        catch(Exception e) {}
    } 
    
    public void destroyShip()
    {
        Actor defender = getOneIntersectingObject(Defender.class);
        if (defender != null) 
        {
            getWorld().removeObjects(getWorld().getObjects(Asteroid.class));
            getWorld().removeObject(defender);
            
            gameover gameover = new gameover();
            getWorld().addObject(gameover, 303, 209);
        }
    }
    
    public void leaveWorld()
    {
        if (getY() >= getWorld().getHeight()-5) 
        {
            getWorld().removeObject(this);
            score.add(-2);
        }
    }
    
    public void vertMove()
    {
        setLocation(getX(),getY()+5);
    }
    
   
}








